/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package validators;
import beans.Usuario;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import rn.UsuarioRN;

/**
 *
 * @author Caio
 */
@FacesValidator("validators.ValidatorUsuario")
public class ValidatorUsuario implements Validator{

    @Override
    public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
        UsuarioRN rn = new UsuarioRN();
        List<Usuario> list = rn.buscaPersonalizada("login", (String) o);
        if(list.size()>0) {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,"Login já existe", "Login já existe"));
        }
        list.clear();
    }
    
}
